package com.wyz.socket.core.base.packet;

import com.wyz.socket.core.base.packet.bytes.BytesReceivePacket;
import com.wyz.socket.core.base.packet.file.FileReceivePacket;
import com.wyz.socket.core.base.packet.stream.StreamDirectReceivePacket;
import com.wyz.socket.core.base.packet.string.StringReceivePacket;

import java.io.File;

import static com.wyz.socket.core.base.packet.Packet.*;
import static com.wyz.socket.core.base.packet.Packet.TYPE_STREAM_DIRECT;

public final class PacketFactory {

    public static AbstractReceivePacket<?, ?> createReceivePacket(byte type, int length , AttachCallback callback){
        switch (type) {
            case TYPE_MEMORY_BYTES: {
                return new BytesReceivePacket(length);
            }
            case TYPE_MEMORY_STRING: {
                return new StringReceivePacket(length);
            }
            case TYPE_STREAM_FILE: {
                return new FileReceivePacket(callback.create(File.class), length);
            }
            case TYPE_STREAM_DIRECT: {
                return new BytesReceivePacket(length);
            }
        }
        return null;
    }

   public interface AttachCallback{
        <T> T create(Class<T> clazz) ;
    }
}
